<template>
  <div :style="{height:'300px',width:'100%'}" />
</template>

<script>
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";

export default {
  name: "IntentionChart",
  mixins: [resize],
  data() {
    return {
      chart: null
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
    }
  },
  created() {
    setTimeout(() => {
      var outProductionCount = 0;
      var publicPraiseCount = 0;
      var certificateCount = 0;
      var intEducationCount = 0;
      var repPurchase = 0;
      this.axios.get("/student/getTall").then(res => {
        for (var i = 0; i < res.data.data.length; i++) {
          if (
            res.data.data[i].teacher == localStorage.username ||
            res.data.data[i].manager == localStorage.username
          ) {
            if (res.data.data[i].outProduction == "true") {
              outProductionCount++;
            }
            if (res.data.data[i].publicPraise == "true") {
              publicPraiseCount++;
            }
            if (res.data.data[i].certificate == "true") {
              certificateCount++;
            }
            if (res.data.data[i].intEducation == "true") {
              intEducationCount++;
            }
            if (res.data.data[i].repPurchase == "true") {
              repPurchase++;
            }
          }
          if (localStorage.position == "2") {
            if (res.data.data[i].outProduction == "true") {
              outProductionCount++;
            }
            if (res.data.data[i].publicPraise == "true") {
              publicPraiseCount++;
            }
            if (res.data.data[i].certificate == "true") {
              certificateCount++;
            }
            if (res.data.data[i].intEducation == "true") {
              intEducationCount++;
            }
            if (res.data.data[i].repPurchase == "true") {
              repPurchase++;
            }
          }
        }

        // 开始绘图数据
        this.chart.setOption({
          color: ["#68aafc"],
          tooltip: {
            trigger: "axis",
            axisPointer: {
              // 坐标轴指示器，坐标轴触发有效
              type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
            }
          },
          xAxis: {
            type: "category",
            data: ["意向脱产", "意向口碑", "意向证书", "意向学历", "意向复购"]
          },
          yAxis: {
            type: "value"
          },
          series: [
            {
              name: "人数",
              type: "bar",
              barWidth: "20%",
              data: [
                outProductionCount,
                publicPraiseCount,
                certificateCount,
                intEducationCount,
                repPurchase
              ]
            }
          ]
        });
      });
    }, 900);
  }
};
</script>

<style>
</style>